package cn.com.guage.dtm.design.pattern.strategy;
// 支付策略接口
interface PaymentStrategy {
    void pay(double amount);
}

// 支付宝支付策略
class AlipayStrategy implements PaymentStrategy {
    @Override
    public void pay(double amount) {
        System.out.println("使用支付宝支付了 " + amount + " 元");
    }
}

// 微信支付策略
class WechatPayStrategy implements PaymentStrategy {
    @Override
    public void pay(double amount) {
        System.out.println("使用微信支付了 " + amount + " 元");
    }
}

// 银行卡支付策略
class BankCardPayStrategy implements PaymentStrategy {
    @Override
    public void pay(double amount) {
        System.out.println("使用银行卡支付了 " + amount + " 元");
    }
}

// 支付上下文类
class PaymentContext {
    private PaymentStrategy strategy;

    public PaymentContext(PaymentStrategy strategy) {
        this.strategy = strategy;
    }

    public void executePayment(double amount) {
        strategy.pay(amount);
    }
}

// 主类
public class 策略模式_支付实现 {
    public static void main(String[] args) {
        // 使用支付宝支付
        PaymentContext alipayContext = new PaymentContext(new AlipayStrategy());
        alipayContext.executePayment(100.0);

        // 使用微信支付
        PaymentContext wechatPayContext = new PaymentContext(new WechatPayStrategy());
        wechatPayContext.executePayment(200.0);

        // 使用银行卡支付
        PaymentContext bankCardPayContext = new PaymentContext(new BankCardPayStrategy());
        bankCardPayContext.executePayment(300.0);
    }
}
